package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	UserName   string `gorm:"type:varchar(20);not null;comment:'用户名'"`
	Phone      string `gorm:"type:char(32);not null;comment:'手机号'"`
	Password   string `gorm:"type:char(32);not null;comment:'密码'"`
	UserStatue int64  `gorm:"type:tinyint(1);default:0;comment:'用户状态:0-正常,1-冻结'"`
}

func (u *User) Find(UserStatue, Page, pageSize int64) (list []*User, err error) {
	if UserStatue == 0 {
		err = DB.Offset(int((Page - 1) * pageSize)).Limit(int(pageSize)).Find(&list).Error
		return
	} else {
		err = DB.Where("user_statue =?", UserStatue).Offset(int((Page - 1) * pageSize)).Limit(int(pageSize)).Find(&list).Error
		return
	}
}

func (u *User) Update(userId, UserStatue int64) error {
	return DB.Model(&u).Where("id =?", userId).Update("user_statue", UserStatue).Error
}
